package com.xyz.controller;

import com.xyz.aop.Param;
import com.xyz.service.SystemService;
import com.xyz.util.dto.DataResult;
import com.xyz.util.dto.LoginInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("system")
public class SystemController {

    private static final Logger logger = LoggerFactory.getLogger(SystemController.class);

    @Autowired
    private SystemService systemService;

    @PostMapping("selectDictByDictType")
    public DataResult selectDictByDictType(
            LoginInfo li,
            @Param String dictTypeCode
    ) {
        try {
            return systemService.selectDictByDictType(li, dictTypeCode);
        } catch (Exception e) {
            logger.error("selectDictByDictType", e);
            return DataResult.build9500();
        }
    }

    @PostMapping("selectSystemLog")
    public DataResult selectSystemLog(
            LoginInfo li,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageNum,
            @Param(type = Param.ParamType.POSITIVE_INTEGER) String pageSize,
            @Param(isRequired = false) String username,
            @Param(isRequired = false, type = Param.ParamType.DATE, rule = "yyyy-MM-dd HH:mm:ss") String beginTime,
            @Param(isRequired = false, type = Param.ParamType.DATE, rule = "yyyy-MM-dd HH:mm:ss") String endTime
    ) {
        try {
            return systemService.selectSystemLog(li, Integer.parseInt(pageNum), Integer.parseInt(pageSize), username, beginTime, endTime);
        } catch (Exception e) {
            logger.error("selectSystemLog", e);
            return DataResult.build9500();
        }
    }


    @PostMapping("selectDictByDictTypeMap")
    public DataResult selectDictByDictTypeMap(LoginInfo li, @Param String dictTypeCode) {
        try {
            return systemService.selectBatchDictByDictType(li, dictTypeCode);
        } catch (Exception e) {
            logger.error("selectDictByDictType", e);
            return DataResult.build9500();
        }
    }

}
